package com.ruoyi.web.controller.basedata;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.PayKind;
import com.ruoyi.basedata.service.IPayKindService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 *  信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-06
 */
@Controller
@RequestMapping("/basedata/paykind")
public class PayKindController extends BaseController
{
    private String prefix = "basedata/payKind";
	
	@Autowired
	private IPayKindService payKindService;
	
	@RequiresPermissions("basedata:paykind:view")
	@GetMapping()
	public String payKind()
	{
	    return prefix + "/payKind";
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("basedata:paykind:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PayKind payKind)
	{
		startPage();
        List<PayKind> list = payKindService.selectPayKindList(payKind);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出列表
	 */
	@RequiresPermissions("basedata:paykind:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayKind payKind)
    {
    	List<PayKind> list = payKindService.selectPayKindList(payKind);
        ExcelUtil<PayKind> util = new ExcelUtil<PayKind>(PayKind.class);
        return util.exportExcel(list, "payKind");
    }
	
	/**
	 * 新增
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存
	 */
	@RequiresPermissions("basedata:paykind:add")
	@Log(title = "", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PayKind payKind)
	{		
		return toAjax(payKindService.insertPayKind(payKind));
	}

	/**
	 * 修改
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		PayKind payKind = payKindService.selectPayKindById(id);
		mmap.put("payKind", payKind);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存
	 */
	@RequiresPermissions("basedata:paykind:edit")
	@Log(title = "", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PayKind payKind)
	{		
		return toAjax(payKindService.updatePayKind(payKind));
	}

	/**
	 * 支付类型修改
	 */
	@Log(title = "支付类型", businessType = BusinessType.UPDATE)
	@RequiresPermissions("basedata:paykind:eidt")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(PayKind payKind) {
		return toAjax(payKindService.changeStatus(payKind));
	}


	/**
	 * 删除
	 */
	@RequiresPermissions("basedata:paykind:remove")
	@Log(title = "", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(payKindService.deletePayKindByIds(ids));
	}

	/**
	 * 校验名字
	 */
	@PostMapping("/checkPaykindUnique")
	@ResponseBody
	public String checkPaykindUnique(PayKind payKind) {
		return payKindService.checkPaykindUnique(payKind);
	}
}
